#ifndef	_PROTOCOL_H_
#define	_PROTOCOL_H_

//
#include "stm32f10x.h"

//#pragma pack(push) //??????
//#pragma pack(pop) //??????
#pragma pack(1)//???4????

typedef struct _Pagheadstruction
{
	u16	Dstaddr;
	u16	Srcaddr;
	u16	Reserved1;
	u16	Reserved2;
	u16	Reserved3;
	u8	Devicetype;
	u8	Protocolversion;
	u16	DataLen;
}Pagheadstruction;

typedef struct _Cmdstruction
{
	u8	CmdGroup;
	u8	Cmd;
	u8	Response;
	u8	Reserved1;
	u8	Reserved2;
}Cmdstruction;

typedef struct _MovieCmdstruction
{
	Cmdstruction	cmdstructions;              
	u8	DeleteAreaNum;			 //??????  1
	u8	AreaNum;				//????     1
	u16	AreaDataLen0;			//	???? 2
	u8	AreaType;				//????
	u16 	AreaX;					//x??
	u16	AreaY;					//y??
	u16	AreaWidth;				//??
	u16	AreaHeight;				//??
	u8      DynamicAreaLoc;			//??????
	u8      Lines_sizes;				//???				
	u8      RunMode	;			//????					
	u16 	Timeout	;			//????			
	u8      Rev1;   				// ???
	u8      Rev2;				// ???
	u8      Rev3;				// ???
	u8 	SingleLine;		//?????? 
	
	u8      NewLine;				//????
	u8 	DisplayMode;			//????
	u8	ExitMode;			//????
	u8	Speed;				//??
	u8	StayTime;			//????
	u32	DataLen;				//????
}MovieCmdstruction; 

typedef struct DISPLAYSTRUCT
{
	u8	Color;
	u16 X;
	u16 Y;
	u8	StayTime;
	u8 Areaid;
	char String[32];
}DisplayStruct;
#pragma pack()

#define LEDRED  1
#define LEDYELLOW  3
#define LEDGREEN  2

u8 Collect_Protocol_Deal(u8 *buffer,u16 *bufferlen);
u16 MakeDataarea(u8 *string,u16 X,u16 Y,u16 Width,u16 Height,u8 staytime,u8 AreaId);
static char * replace_string (char * string, const char * source, const char * destination )  ;
int ReplaceStr(char *sSrc,const char *sMatchStr,const char *sReplaceStr);
u8 Commond_Setbright(u8 strength,u8 *string);
void DisplayTask(float gas ,float toxic);
void Get_Meter_Info(void);
void Write_Meter_Info(void);
void Judgeinterval(void);

#endif